<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<head th:replace="~{segmentation/_right_bottom_header::_header_common(~{::title},~{::link},~{::style})}">
    <meta charset="utf-8">
    <title>用户权限新增</title>
    <link>
    <style type="text/css"></style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>用户权限新增</legend>
        </fieldset>
        <form class="layui-form" id="rightsFormAdd" action="">
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="required-red">*</span>启用状态</label>
                <div class="layui-input-block">
                    <input th:each="item : ${@typeServiceImpl.findByParentCodeList('enableStatus')}"
                           th:title="${item.typeName}"
                           th:value="${item.typeValue}"
                           th:checked="${1 == item.typeValue}"
                           type="radio" name="enableStatus" lay-verify="required|enableStatus"
                           lay-verType="tips">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="required-red">*</span>设置邀请员工权限（7777=无权限，9999=有权限）</label>
                <div class="layui-input-block">
                    <input type="text" name="invitationStatus" id="invitationStatus" lay-verify="required|number|invitationStatus"
                           lay-verType="tips"
                           placeholder="请输入设置邀请员工权限（7777=无权限，9999=有权限）" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="required-red">*</span>设置返利比例权限（7777=无权限，9999=有权限）</label>
                <div class="layui-input-block">
                    <input type="text" name="rebateRatioStatus" id="rebateRatioStatus" lay-verify="required|number|rebateRatioStatus"
                           lay-verType="tips"
                           placeholder="请输入设置返利比例权限（7777=无权限，9999=有权限）" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item custom-text-align"
                 sec:authorize="hasPermission(#authorization.authentication,'button','RIGHTS_LIST_MANAGEMENT:add')">
                <a class="layui-btn" lay-submit="" lay-filter="rightsFormAddSubmit">保存</a>
            </div>
        </form>
    </div>
</div>

<div th:replace="~{segmentation/_tail::_tail_common}"></div>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script th:inline="javascript">
    /*<![CDATA[*/
    [# sec:authorize="hasPermission(#authorization.authentication,'button','RIGHTS_LIST_MANAGEMENT:add')"]
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer;


        //自定义验证规则
        form.verify({
            enableStatus: function (value) {
                if (value.length > 10) {
                    return '启用状态最多10个字符';
                }
            },
            invitationStatus: function (value) {
                if (value.length > 10) {
                    return '设置邀请员工权限（7777=无权限，9999=有权限）最多10个字符';
                }
            },
            rebateRatioStatus: function (value) {
                if (value.length > 10) {
                    return '设置返利比例权限（7777=无权限，9999=有权限）最多10个字符';
                }
            },
        });

        //监听提交
        form.on('submit(rightsFormAddSubmit)', function (data) {
            $.ajax({
                type: 'POST',
                url: '/module/user/rights/save',
                data: data.field,
                dataType: 'json',
                success: function (data) {
                    if (data.code == Result.SUCCESS) {
                        layer.msg('成功!', {
                            icon: 1,
                            shade: [0.3, '#f5f5f5'],
                            time: 1500
                        }, function () {
                            $("#rightsList", window.parent.document).attr('value', 1);
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    } else {
                        layer.msg(data.msg, {
                            icon: 2,
                            time: 3000
                        });
                    }
                }, error:function(data) {
                    console.log(data);
                },
            });
            return false;//返回false防止重复提交
        });
    });
    [/]
    /*]]>*/
</script>

</body>
</html>